﻿using System.ComponentModel;
using System.Reflection;

namespace DataLook.Controllers
{
	internal class ResultModel
	{
		/// <summary>
		/// 结果状态：0;成功 1：失败
		/// </summary>
		public int Code { get; set; }
		/// <summary>
		/// 提示信息
		/// </summary>
		public string Message { get; set; }
		/// <summary>
		/// 结果集合
		/// </summary>
		public string Data { get; set; }

		/// <summary>
		/// 返回结果构造
		/// </summary>
		public ResultModel()
		{
			this.Code = 0;
		}

		/// <summary>
		/// 返回结果构造
		/// </summary>
		/// <param name="value">错误类型值</param>
		public ResultModel(ErrorType value)
		{
			FieldInfo fi = value.GetType().GetField(value.ToString());
			DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
			this.Message = (attributes.Length > 0) ? attributes[0].Description : value.ToString();
			this.Code = 0;
			// this.ErrorCode = (int)value;

		}

		/// <summary>
		/// 设置错误值
		/// </summary>
		/// <param name="value">错误类型值</param>
		public void SetValue(ErrorType value)
		{
			FieldInfo fi = value.GetType().GetField(value.ToString());
			DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
			this.Message = (attributes.Length > 0) ? attributes[0].Description : value.ToString();
			this.Code = (int)value;
		}
		/// <summary>
		/// 设置错误值
		/// </summary>
		/// <param name="errorMsg">错误类型消息</param>
		///  /// <param name="errorCode">错误类型码</param>
		public void SetValue(string errorMsg, int errorCode)
		{
			this.Message = errorMsg;
			this.Code = errorCode;
		}

		/// <summary>
		/// 请求处理错误类型
		/// </summary>
		public enum ErrorType
		{

			#region 请求处理
			/// <summary>
			/// 操作成功
			/// </summary>
			[Description("操作成功")]
			Success = 0,

			/// <summary>
			/// 操作失败
			/// </summary>
			[Description("操作失败")]
			HasError = 1,

			/// <summary>
			/// 余额支付成功
			/// </summary>
			[Description("余额支付成功")]
			BalancePay = 100001,
			#endregion 请求处理

			 
		}
	}
}